home *** CD-ROM | disk | FTP | other *** search
- Path: prairienet.org!wemccaug
- From: wemccaug@prairienet.org (Wendy E. McCaughrin)
- Newsgroups: comp.lang.c++
- Subject: Re: Fastest Sorting Algorithm?
- Date: 13 Apr 1996 22:31:03 GMT
- Organization: University of Illinois at Urbana
- Message-ID: <4kp9v7$qpd@vixen.cso.uiuc.edu>
- References: <4k4unk$15qe@sol.caps.maine.edu> <Dou55w.7MB@novice.uwaterloo.ca> <DpAxtI.3w9@undergrad.math.uwaterloo.ca>
- Reply-To: wemccaug@prairienet.org (Wendy E. McCaughrin)
- NNTP-Posting-Host: firefly.prairienet.org
-
-
- In a previous article, slary61@maine.maine.edu (Scott) says:
-
- >"And how would you make it faster still?" He couldn't come up with
- >> >much...end of interview.
- >> Mybe they meant tweaking stratigies for quicksort like how
- >> to choose a pivot element. Who knows.
- >>
- >> --
- >It's hard to beat the sort invented by Hoare at O(2log n). As far
- >as comparison sorts go, I don't think its been beaten.
- >
- >
- Actually, the first author is very much on the right track: picking
- the "right" pivot element is one of the best ways to speed Quicksort
- up. Recall that, in the best case, you would like the pivot to approx-
- imate the median so as to bisect the array as much as possible. In the
- extreme case where you pick a minimum (or maximum) for the pivot, you
- have almost as much work to do as the previous iteration/recursion.
-
- Of course, a second approach is to remove the recursion (much easier).
-
- Third, know when to stop quicksorting and start "straight" sorting
- (via selection sort, e.g.) the remaining small sub-arrays. I believe
- the estimates for this size range from 5 to 15.
-
- Fourth, consider the task of comparison itself. If "comparison"
- involves something more complex than < or >, consider opportunities
- for optimizing your comparison operator.
-
- Fifth, if the array elements are non-scalar aggregates, consider
- sorting instead an "index vector" of pointers to the aggregates
- to reduce the amount of data-movement entailed in partitioning
- your array.
-
- Sixth, if the array is very large (so that virtual memory loads
- become problematical), consider sorting only sub-arrays of man-
- ageable size, then merge-sorting these into the final result.
-
- Of course, the story by no means ends here -- just a sampler to
- show how much more can be done. And of course, Hoare _is_ to be
- commended upon what has turned out to be in practice a highly
- efficient algorithm, often beating heapsort.
-
- sjm
-
-